import threading

class Counter:
    def __init__(self):
        self.count = 0
        self.lock = threading.Lock()

    def increment(self):
        with self.lock:
            self.count += 1

    def decrement(self):
        with self.lock:
            self.count -= 1

    def get_count(self):
        with self.lock:
            return self.count

def worker(counter):
    for _ in range(1000):
        counter.increment()
    for _ in range(1000):
        counter.decrement()

if __name__ == "__main__":
    counter = Counter()
    threads = []

    for _ in range(10):
        t = threading.Thread(target=worker, args=(counter,))
        threads.append(t)
        t.start()

    for t in threads:
        t.join()

    print(f"最终计数器的值: {counter.get_count()}")